package com.example.controller.siyunKefuController;

import com.example.pojo.siyunKefu.KefuCishu;
import com.example.pojo.siyunKefu.SiyunKefu;
import com.example.pojo.siyunKefu.SiyunKefuIssue;
import com.example.service.siyunKefuService.SiyunKefuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * @ClassName: ***
 * @Description: ***
 * @author: ***
 * @date: 2022/12/7 19:11
 */
@RestController
@CrossOrigin
public class SiyunKefuController {
    @Autowired
    private SiyunKefuService siyunKefuService;
    @Value("${file.path}")
    private String path;
    /**
    * @Author: lzr
    * @Description: 查找客服表中所有接待人数和接待次数
    * @DateTime: 19:12 2022/12/7
    * @Params:
    * @Return
    */
    @PostMapping("/getLishijilu")
    public KefuCishu getLishijilu(@RequestBody SiyunKefu siyunKefu){
        return siyunKefuService.getLishijilu(siyunKefu);
    }
    /**
    * @Author: lzr
    * @Description: 查找今日新增的接待人数和接待次数
    * @DateTime: 13:34 2022/12/8
    * @Params: 
    * @Return 
    */
    @PostMapping("/todayShuju")
    public KefuCishu todayShuju(SiyunKefu siyunKefu){
        return siyunKefuService.todayShuju(siyunKefu);
    }
    /**
    * @Author: lzr
    * @Description: 查找所有客服聊天状态
    * @DateTime: 14:01 2022/12/8
    * @Params: 
    * @Return 
    */
    @PostMapping("/getKefu")
    public List<SiyunKefu> getKefu(){
       return siyunKefuService.getKefu();
    }
    /**
    * @Author: lzr
    * @Description: 改变机器人的启用状态
    * @DateTime: 14:33 2022/12/8
    * @Params:
    * @Return
    */
    @PostMapping("/getEnable")
    public boolean getEnable(@RequestBody SiyunKefu siyunKefu){
        return siyunKefuService.getEnable(siyunKefu);
    }
    /**
    * @Author: lzr
    * @Description: 删除某条客服信息
    * @DateTime: 14:52 2022/12/8
    * @Params:
    * @Return
    */
    @PostMapping("/getDeleteKefu")
    public boolean getDeleteKefu(@RequestBody SiyunKefu siyunKefu){
        return siyunKefuService.getDeleteKefu(siyunKefu);
    }
    /**
    * @Author: lzr
    * @Description: 添加图片
    * @DateTime: 13:27 2022/12/9
    * @Params: 
    * @Return 
    */
    @RequestMapping("/addpagepromige")
    public int FilePros(MultipartFile file){
        SiyunKefu siyunKefu = new SiyunKefu();
        String originalFilename = file.getOriginalFilename();
        int i = originalFilename.indexOf(".");
        String substring = originalFilename.substring(i);
        UUID uuid = UUID.randomUUID();
        File file1 = new File(path+uuid+substring);
        try {
            file.transferTo(file1);
            siyunKefu.setToimg("http://localhost:8091/Img/"+uuid+substring);
            siyunKefuService.getAddRobot(siyunKefu);
            return siyunKefu.getToid();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return siyunKefu.getToid();
    }
    /**
    * @Author: lzr
    * @Description: 添加机器人
    * @DateTime: 13:28 2022/12/9
    * @Params:
    * @Return
    */
    @PostMapping("/getAddRobot")
    public boolean getAddRobotTwo(@RequestBody SiyunKefu siyunKefu){
        System.out.println(siyunKefu);
        return siyunKefuService.getAddRobotTwo(siyunKefu);
    }
    /**
    * @Author: lzr
    * @Description: 客服回答问题
    * @DateTime: 20:17 2022/12/15
    * @Params:
    * @Return
    */
    @PostMapping("/getReply")
    public List<SiyunKefuIssue> getReply(@RequestBody SiyunKefuIssue siyunKefuIssue){
        return siyunKefuService.getReply(siyunKefuIssue);
    }
    /**
    * @Author: lzr
    * @Description: 可以问客服的问题
    * @DateTime: 20:18 2022/12/15
    * @Params:
    * @Return
    */
    @PostMapping("/getIssue")
    public List<SiyunKefuIssue> getIssue(@RequestBody SiyunKefuIssue siyunKefuIssue){
        return siyunKefuService.getIssue(siyunKefuIssue);
    }
    /**
    * @Author: lzr
    * @Description: 获取全部人工客服渲染到页面
    * @DateTime: 9:59 2022/12/16
    * @Params: 
    * @Return 
    */
    @PostMapping("/getAllKefu")
    public List<SiyunKefu> getAllKefu(){
        return siyunKefuService.getAllKefu();
    }
    /**
    * @Author: lzr
    * @Description: 首次聊天时间以及内容记录
    * @DateTime: 9:48 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getFirstLiaotian")
    public Integer getAddLiaotian(@RequestBody SiyunKefu siyunKefu){
        Integer addLiaotian = siyunKefuService.getAddLiaotian(siyunKefu);
        return siyunKefu.getId();
    }
    /**
    * @Author: lzr
    * @Description: 最后一次聊天记录和聊天时间
    * @DateTime: 14:34 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getLastLiaotian")
    public boolean getUpdateLiaotian(@RequestBody SiyunKefu siyunKefu){
        boolean updateLiaotian = siyunKefuService.getUpdateLiaotian(siyunKefu);
        return updateLiaotian;
    }
    /**
    * @Author: lzr
    * @Description: 今天的全部数据
    * @DateTime: 18:50 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getTodayLiaotian")
    public List<SiyunKefu> getTodayLiaotian(){
        return siyunKefuService.getTodayLiaotian();
    }
    /**
    * @Author: lzr
    * @Description: 本周的全部数据
    * @DateTime: 20:15 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getToweekLiaotian")
    public List<SiyunKefu> getToweekLiaotian(){
        return siyunKefuService.getToweekLiaotian();
    }
    /**
    * @Author: lzr
    * @Description: 本月的全部数据
    * @DateTime: 20:20 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getTomonthLiaotian")
    public List<SiyunKefu> getTomonthLiaotian(){
        return siyunKefuService.getTomonthLiaotian();
    }
    /**
    * @Author: lzr
    * @Description: 全部数据
    * @DateTime: 20:22 2022/12/23
    * @Params:
    * @Return
    */
    @PostMapping("/getAllLiaotian")
    public List<SiyunKefu> getAllLiaotian(){
        return siyunKefuService.getAllLiaotian();
    }
}
